<template>
	<view>
		<view>
			<uni-nav-bar shadow left-icon="left" dark title="合同审核详细" @clickLeft="back()" />
		</view>
		
		<view>
			<uni-card>
			<uni-row>
				<text style="font-weight: 600;">合同编号:</text>{{forms.contractNum}}
			</uni-row>
			<uni-row>
				<text style="font-weight: 600;">合同名称:</text>{{forms.contractName}}
			</uni-row>
		    <uni-row>
			    <text style="font-weight: 600;">合同类型:</text>{{forms.contractType}}
			</uni-row>
			<uni-row>
			    <text style="font-weight: 600;">合同模版:</text>{{forms.templateName}}
			</uni-row>
			
			<uni-row><text style="font-weight: 600;">公司名称:</text>{{forms.companyName}}</uni-row>
		   
			<uni-row><text style="font-weight: 600;">供应商名称:</text>{{forms.supplierName}}</uni-row>
			
			<uni-row><text style="font-weight: 600;">付款方式:</text>{{forms.paymentMethod}}</uni-row>
		
			<uni-row>
			<view  v-if="forms.status==0"><text style="font-weight: 600;">合同状态:</text><text>待审核</text></view>
				<view  v-if="forms.status==1"><text style="font-weight: 600;">合同状态:</text><text>待审批</text></view>
			<view  v-if="forms.status==2"><text style="font-weight: 600;">合同状态:</text><text >已通过</text></view>
			<view  v-if="forms.status==3"><text style="font-weight: 600;">合同状态:</text><text>已驳回</text></view>
			</uni-row>
			<uni-row><text style="font-weight: 600;">合同有效期:</text>{{forms.contractSigningDate}}到{{from.contractExpirationDate}}</uni-row>
			<uni-row><text style="font-weight: 600;">发票类型:</text>{{forms.invoiceType}}</uni-row>
			<uni-row><text style="font-weight: 600;">合同总金额:</text>{{forms.totalContractAmount}}(元)</uni-row>
			<uni-row><text style="font-weight: 600;">合同总金额(大写):</text>{{forms.totalContractAmountInWords}}</uni-row>
			<uni-row><text style="font-weight: 600;">审批意见:</text><uni-easyinput type="textarea" v-model="approvalOpinions"></uni-easyinput></uni-row>
			
			<uni-row style="text-align: center;margin-top: 20rpx;" v-if="forms.status=='0'|| forms.status=='1'&& forms.isEx=='T' ">
				<uni-col :span="12"><button size="mini" type="primary" @click="add()">通过</button></uni-col>
				<uni-col :span="12"><button size="mini" type="warn" @click="getOut()">驳回</button></uni-col>
			</uni-row>
			<view style="margin-top: 20rpx;">
				<uni-segmented-control :current="current" :values="items" styleType="button" activeColor="#ffaa00" @clickItem="onClickItem" style="background-color: #fff"  />
			</view>
			<view>
				<view v-if="current === 0">
				<uni-row><text style="font-weight: 600;">合同条款第一条:</text><uni-easyinput type="textarea" v-model="forms.contractItem1"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第二条:</text><uni-easyinput type="textarea" v-model="forms.contractItem2"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第三条:</text><uni-easyinput type="textarea" v-model="forms.contractItem3"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第四条:</text><uni-easyinput type="textarea" v-model="forms.contractItem4"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">合同条款第五条:</text><uni-easyinput type="textarea" v-model="forms.contractItem5"></uni-easyinput></uni-row>
				<uni-row><text style="font-weight: 600;">其他条款:</text><uni-easyinput type="textarea" v-model="forms.otherTerms"></uni-easyinput></uni-row>
				<uni-row>
					<text style="font-weight: 600;">验收标准:</text>
				<uni-easyinput type="textarea" v-model="from.acceptanceStandard"></uni-easyinput>
				</uni-row>
				<uni-row>
					<text style="font-weight: 600;">违约责任:</text>
					<uni-easyinput type="textarea" v-model="from.breachOfContract"></uni-easyinput>
				</uni-row>
				<uni-row>
					<text style="font-weight: 600;">合同备注:</text>
					<uni-easyinput type="textarea" v-model="from.contractRemarks"></uni-easyinput>
				</uni-row>
				</view>
				<view v-if="current === 1">
					<uni-table border stripe >
							<uni-tr style="white-space: nowrap;text-align: center;font-size: 12rpx">
								<uni-th align="center">物料名称</uni-th>
								<uni-th align="center">数量</uni-th>
								<uni-th align="center">单位</uni-th>
								<uni-th align="center">单价</uni-th>
								<uni-th align="center">总价</uni-th>
								<uni-th align="center">交货日期</uni-th>
							</uni-tr>
							<uni-tr v-for="(item,index) in tables" :key="index" style="white-space: nowrap;text-align: center;font-size: 12rpx">
								<uni-td align="center">{{item.materialName}}</uni-td>
								<uni-td align="center">{{item.quantity}}</uni-td>
								<uni-td align="center">{{item.unit}}</uni-td>
								<uni-td align="center">{{item.unitPrice}}</uni-td>
								<uni-td align="center">{{item.totalPrice}}</uni-td>
								<uni-td align="center">{{item.deliveryDate}}</uni-td>
							</uni-tr>
					
						</uni-table>
					</view>
					
					<view v-if="current === 2">
						<uni-table border stripe >
								<uni-tr style="white-space: nowrap;text-align: center;font-size: 12rpx;">
									<uni-th align="center">序号</uni-th>
									<uni-th align="center">流程</uni-th>
									<uni-th align="center">状态</uni-th>
									<uni-th align="center">审批人</uni-th>
									<uni-th align="center">审批意见</uni-th>
									<uni-th align="center">审批日期</uni-th>
								</uni-tr>
								<uni-tr v-for="(items,indexs) in ReviewReviewId" :key="indexs" style="white-space: nowrap;text-align: center;font-size: 12rpx">
									<uni-td align="center">{{items.seqNum}}</uni-td>
									<uni-td align="center">{{items.process}}</uni-td>
									<uni-td align="center"><text v-if="items.status==0">未完成</text></uni-td>
									<uni-td align="center"><text v-if="items.status==1">已完成</text></uni-td>
									<uni-td align="center">{{items.realName}}</uni-td>
									<uni-td align="center">{{items.approvalOpinions}}</uni-td>
									<uni-td align="center">{{items.approvalData}}</uni-td>
								</uni-tr>
						
							</uni-table>
						</view>
					<view v-if="current === 3">
						<view style="text-align: center;">					
					
							 <web-view :src="saveUrl"></web-view>	
					    </view>
					</view>
				</view>
	
				
			
			</uni-card>
		</view>
		
		
	</view>
</template>

<script>
	import {goBack,editSave,reviewFormEditUI,reviewProcessTable,ReviewProcessFormReviewId,DocumentFormDatatable} from "@/api/system/user"
	import { toast, showConfirm, tansParams } from '@/utils/common'
	export default {
		data() {
			return {
				saveUrl:null,
				current:0,
				from:null,
				forms:null,
				tables:null,
				approvalOpinions:null,
				ReviewReviewId:null,
				items: ['合同条款','采购明细','审批流程','附件'],		
			}
		},
		onLoad() {
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('acceptDataFromOpenerPage', (data) => {
				this.from = data.data
				})
			this.docLabel='contractFile'
			DocumentFormDatatable(this.from.contractNum,this.docLabel).then(res=>{
			
			this.saveUrl='http://39.103.203.89:7072/temp/cgscrm/doc'+res.rows[0].saveUrl
					
			})	
			this.get()
			
		},
	
		methods: {
			get(){
			  reviewFormEditUI(this.from.rowId).then(res=>{
		  
				  this.contractId=res.data.contractId
				  this.forms=res.data.form
			     //查询物料明细
				 reviewProcessTable(this.from.rowId).then(res=>{
			     this.tables=res.rows
			     	})
				 ReviewProcessFormReviewId(this.from.rowId).then(res=>{
			     this.ReviewReviewId=res.rows
			     	})	

              })
				
			},
			
		
			add(){
				
				if(this.approvalOpinions==null){
					toast("请填写审批意见")
					return;
				}
				
				this.forms.approvalOpinions=this.approvalOpinions
				editSave(this.forms).then(res=>{
					this.$tab.reLaunch('/pages/work/purchaser/contract_review')
				})
			
			
			},
			
			getOut(){
				
				if(this.approvalOpinions==null){
					toast("请填写审批意见")
					return;
				}
				goBack(this.forms.rowId,this.approvalOpinions).then(res =>{
					this.$tab.reLaunch('/pages/work/purchaser/contract_review')
				})
			},
			back(){
					this.$tab.reLaunch('/pages/work/purchaser/contract_review')
			},
			onClickItem(e) {
						if (this.current !== e.currentIndex) {
							this.current = e.currentIndex
						}
					},
		}
	}
</script>

<style>

</style>
